Here is an example that we have borrowed from the emsarray notebooks showing how to construct a basic animation plot using the eReef's GBR1 data.
If you have not done so, a good precursor to this example is the basic plotting example, plot.ipynb. Please consider running that example first to see the basics of how we can use the eREEFS vis portal to find interesting data.
From where we left our vis portal in the plotting example, we have an ammonia layer added, and visualised on the map.

From this, we can generate an animation from within the visportal by clicking the movie camera icon in the top right corner on our layer box. This should bring up an animation screen as shown below.

Using the same data we plotted for our simple plot, we will now go over how we can use the data we found on the eReefs portal to run some emsarray animations of our own.
import datetime
import emsarray as ems
from matplotlib.figure import Figure
from IPython.display import HTML
Set up the environment...
%matplotlib notebook
# The coastlines used in the maps have some bad polygons,
# which causes some warnings. Lets turn those off.
import shapefile
shapefile.VERBOSE = False
Let us use ems array to create an animation from the GBR4 ammonia layer we added.
dataset = ems.open_dataset("https://dapds00.nci.org.au/thredds/dodsC/fx3/model_data/gbr4_bgc_GBR4_H2p0_B2p0_Chyd_Dcrt.ncml")
# # Create the animation
from emsarray.utils import datetime_from_np_time
def make_title(np_time):
"""Generate a title for a frame of animation."""
long_name = "Sea surface height"
py_time = datetime_from_np_time(np_time)
return f'{long_name}\nTime: {py_time:%Y-%m-%d %H:%M}'
depth_anim = dataset.isel(time=-1).ems.animate_on_figure(
figure=Figure(figsize=(8, 5), dpi=100),
scalar='temp', interval=100, repeat='bounce',
coordinate='k')
HTML(depth_anim.to_jshtml())
Animations can be rendered to video files in two different ways. Both approaches require ffmpeg to be installed. If you do not already have this installed, you can install it with:
$ conda install ffmpeg
You can render to an embeded video by calling anim.to_html5_video() instead.
HTML(depth_anim.to_html5_video())
You can export the animation to a file using anim.save().
import os.path
animation_path = os.path.abspath("oceanmap-animation.mp4")
depth_anim.save(animation_path, writer='ffmpeg_file')
print("Saved to", animation_path)
Saved to /home/wil9e0/Programming/EMSArrayTutorials/oceanmap-animation.mp4